<?php
namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;

class Pl5 extends Command
{
    protected function configure()
    {
        $this->setName('pl5')
            ->setDescription('pl5')
            ->addArgument('all', Argument::OPTIONAL, '获取所有数据');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln(date('Y-m-d H:i:s').' pl5 start');
        $service = new \app\service\Pl5;

        $all = $input->getArgument('all');
        if ($all !== null && strtolower($all) === 'all') {
            $res = $service->getAll(243);
        } else {
            $retryCount = 360;
            eg:
            $res = $service->getLast();
            if (!$res['status'] && $res['code'] === 25052801 && $retryCount < 10) {
                $retryCount++;
                sleep(10);
                goto eg;
            }
        }

        if (!$res['status']) {
            return $output->writeln(date('Y-m-d H:i:s').':'.var_export($res, true));
        }

        $output->writeln(date('Y-m-d H:i:s').' pl5 end');
    }
}